package com.example.demo.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.example.demo.entity.User;

@Controller
public class RedirectController {

	
	@RequestMapping("redirect")
	public String redi() {
		return "redirect:http://www.baidu.com";
	}
	
	@RequestMapping("forward")
	public String forward(Map<String,Object> map) {
		map.put("name","张三");
		return "forward:aaa";
	}
	
	@RequestMapping("aaa")
	@ResponseBody
	public Object handler(HttpServletRequest req) {
		if(1==1)throw new NullPointerException("我是异常");
		return "我是aaa"+req.getAttribute("name");
	}
	
	@RequestMapping("view")
	public ModelAndView goView() {
		Map<String, Object> model = new HashMap<String,Object>();
		model.put("info", "this is my modelandview");
		ModelAndView modelAndView = new ModelAndView("view", model);
		return modelAndView;
	}
	
	@RequestMapping("hhh1")
	@ResponseBody
	public Object haha1() {
		User user = new User();
		user.setName("张三");
		user.setAge(18);
		return user;
	}
	
	
}
